#include <iostream>
#include <algorithm>
using namespace std;
void merge(int arr[], int L, int mid, int R, int sz)
{
	int helper[1000] = { 0 };
	for (int i = 0; i < sz; i++)
		helper[i] = arr[i];
	int left = L;
	int right = mid + 1;
	int current = L;
	while (left <= mid && right <= R)
	{
		if (helper[left] <= helper[right])
		{
			arr[current] = helper[left];
			current++;
			left++;
		}
		else
		{
			arr[current] = helper[right];
			current ++;
			right++;
		}
	}
	while (left <= mid)
	{
		arr[current] = helper[left];
		current++;
		left++;
	}
}
void mergeSort(int arr[], int L, int R,int sz)
{
	if (L > R)return;
		int mid = L + ((R - L) >> 1);
		mergeSort(arr, L, mid,sz);
		mergeSort(arr, mid + 1, R,sz);
		merge(arr, L, mid, R,sz);
}
int main()
{
	int arr[] = { 19 ,40 ,97 ,62 ,67 ,65, 5 ,88 ,36 ,77 ,32 ,46 ,93 ,85 ,2 ,99 ,94 ,61 ,98 ,75 ,74 ,25 ,80 ,49 ,17 ,16 ,90 ,70 ,72 ,30 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	mergeSort(arr, 0, sz - 1,sz);
	for (int i = 0; i < sz; i++)
	{
		cout << arr[i] << "  ";
	}
	cout << endl;
	system("pause");
	return 0;
}